<template>
	<view>
		<u-popup v-model="show" mode="bottom" border-radius="40" :mask-close-able="false">
			<view class="search">
				<image src="../../static/sousuo1.png" mode=""></image>
				<input type="text" v-model="search" @confirm="suosuo" placeholder="输入酒名搜索" placeholder-class="pclass" />
			</view>
			<radio-group @change="changeRadio">
				<scroll-view :scroll-y="true" style="height: 510rpx;padding: 30rpx 0;" @scrolltolower="scrolltolower">
					<view class="item" v-for="(item,index) in list" :key="index">
						<view class="left">
							{{item.goods_name}}
						</view>
						<radio :value="String(index)" color="#934BD7" :checked="item.checked" />
					</view>
					<view class="null" v-if="list.length==0">
						<u-empty text="暂无可存的酒" mode="data"></u-empty>
					</view>
				</scroll-view>
			</radio-group>
			<view class="foot">
				<view class="cancel" @click="cancel">
					取消
				</view>
				<view class="confirm" @click="confirm">
					确认
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	// import common from '../../common/common.js'
	export default {
		name: "dwonSelect",
		data() {
			return {
				show: false,
				search: "",
				// list:[]
				list: [],
				page: 1,
				rows: 9999999999,
				current: "",
			};
		},
		methods: {
			quipmentLists(id) {
				this.$request("api/Index/goodsList",{search:this.search}).then(res => {
					if (res.code == 1) {
						this.list = res.data
						for (var i = 0; i < this.list.length; i++) {
							if (id == this.list[i].id) {
								this.list[i].checked = true
							} else {
								this.list[i].checked = false
							}
						}
					}
				})
			},
			changeRadio(e) {
				this.current = e.detail.value
				console.log(e)
			},
			suosuo() {
				this.page == 1
				this.quipmentLists()
			},
			changeShow(e, id) {
				this.show = e
				this.page == 1
				this.quipmentLists(id)

				console.log()

			},
			cancel() {
				this.show = false
			},
			confirm() {
				if (this.current === '') {
					uni.showToast({
						title: '请选择设备',
						icon: 'none'
					})
					return;
				}
				var item = {
					name: this.list[this.current].goods_name,
					id: this.list[this.current].id,
					type:this.list[this.current].wine_type
				}
				this.show = false
				this.$emit('getData', item)

			},
			scrolltolower() {
				console.log('到达底部')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pclass {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #8A8A8A;
	}

	.null {
		padding-top: 100rpx;
		text-align: center;
		color: #8A8A8A;
	}

	.item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 103rpx;
		margin: 0 28rpx;
		padding: 0 20rpx;
		border-bottom: 1rpx solid rgba($color: #BFBFBF, $alpha: 0.39);
	}

	.foot {
		display: flex;
		align-items: center;

		.cancel {
			width: 50%;
			height: 102rpx;
			background: #EEEEEE;
			line-height: 102rpx;
			text-align: center;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #383737;
		}

		.confirm {
			width: 50%;
			height: 102rpx;
			background: #010B24;
			line-height: 102rpx;
			text-align: center;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}

	.search {
		height: 76rpx;
		background: #EEEEEE;
		border-radius: 38rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 0 32rpx;
		margin-top: 40rpx;

		image {
			width: 31rpx;
			height: 31rpx;
		}

		input {
			margin-left: 10rpx;
			text-align: center;
		}
	}
</style>
